﻿using System.Threading;
using System.Threading.Tasks;
using K9Nano.Admin.Weixin.Dto;
using K9Nano.Application;
using Microsoft.AspNetCore.Authentication;

namespace K9Nano.Admin.Weixin
{
    public interface IWeixinAppService : IApplicationService
    {
        /// <summary>
        /// 获取绑定的用户
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cancellation"></param>
        /// <returns>成功返回用户凭证，否则返回null</returns>
        Task<AuthenticationTicket> WeixinAuthenticateAsync(WeixinMpLoginModel model, CancellationToken cancellation);

        /// <summary>
        /// 绑定用户
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cancellation"></param>
        Task WeixinMpBindAsync(WeixinMpBindModel model, CancellationToken cancellation);

        /// <summary>
        /// 微信解绑
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        Task WeixinUnbindAsync(WeixinMpUnbindModel model, CancellationToken cancellation);

        /// <summary>
        /// 获取客户端
        /// </summary>
        /// <param name="clientId"></param>
        /// <returns></returns>
        ValueTask<IdentityServer4.Models.Client> GetClientAsync(string clientId, CancellationToken cancellation);

        /// <summary>
        /// 校验客户端认证的回调地址是否合法
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="redirectUrl"></param>
        /// <returns></returns>
        ValueTask<bool> ValidateRedirectUrlAsync(string clientId, string redirectUrl);

        /// <summary>
        /// 是否已经绑定
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="appId"></param>
        /// <param name="openId"></param>
        /// <param name="unionId"></param>
        /// <param name="cancellation"></param>
        /// <returns></returns>
        ValueTask<bool> IsBoundAsync(string clientId, string appId, string openId, string unionId,
            CancellationToken cancellation);
    }
}